package moo.stargalaxy_bungee.config;

import moo.stargalaxy_bungee.GalaxyBunGee;
import moo.stargalaxy_bungee.api.GalaxyBungeeAPI;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

public class Config {

    private static Configuration configuration;
    public static String version = "1.0.0";

    public static void loadConfig(){
        if (!GalaxyBunGee.getPlugin().getDataFolder().exists()){
            GalaxyBunGee.getPlugin().getDataFolder().mkdir();
        }
        File file = new File(GalaxyBunGee.getPlugin().getDataFolder(), "config.yml");
        if (!file.exists()) {
            try (InputStream in = GalaxyBunGee.getPlugin().getResourceAsStream("config.yml")) {
                Files.copy(in, file.toPath());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(GalaxyBunGee.getPlugin().getDataFolder(), "config.yml"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Configuration getConfiguration() {
        return configuration;
    }

    public static void setConfiguration(Configuration configuration) {
        Config.configuration = configuration;
    }
}
